<%@page import="com.biz.ProTypeBizImpl"%>
<%@page import="com.entity.ProType"%>
<%@page import="com.entity.UserInfo"%>
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>增加商品</title>
    
	<meta charset="UTF-8">
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="css/add-mod-style.css">
	<style type="text/css">
		form{
			margin:0px auto;
			width: 600px;
			height: 100%;
		}
	</style>
	<script src="js/jquery-1.12.4.js"></script>
	<script type="text/javascript">
		function checkPname(){
			var pname=$("#pname").val();
			$("#pname+span").html("");
			if(pname==''){
				$("#pname+span").html("名称不能为空");
				return false;
			}
			return true;
		}
		
		function checkPrice(){
			var price=$("#price").val();
			$("#price+span").html("");
			if(price==''){
				$("#price+span").html("价格不能为空");
				return false;
			}else if(isNaN(price) || parseFloat(price)<0){
				$("#price+span").html("价格不符合规范");
				return false;
			}
			return true;
		}
		
		function checkKind(){
			var price=$("#kind").val();
			$("#price+span").html("");
			if(price==''){
				$("#price+span").html("价格不能为空");
				return false;
			}else if(isNaN(price) || parseFloat(price)<0){
				$("#price+span").html("价格不符合规范");
				return false;
			}
			return true;
		}
		$(function(){
			$("#pname").blur(function(){
				checkPname();
			});
			$("#price").blur(function(){
				checkPrice();
			});
			$("#addform").submit(function(){
				if(checkPname() && checkPrice()){
					return true;
				}
				return false;
			});
			
			$("input[name='addimgfile']").click(function(){
				$("p[name='imgfile']:last").after($("p[name='imgfile']:eq(0)").clone(true));
			});
			$("input[name='del']").click(function(){
					$(this).parent().remove();
			});
			
			$.post("admin/protype/querypt","",function(protypes){
				for(var i=0;i<protypes.length;i++){
					$("#kind").append("<option value="+protypes[i].id+">"+protypes[i].tname+"</option>");
				}
			},"json");
		});
	</script>
  </head>
  <body>
    <form action="admin/product/doAdd" method="post" id="addform" enctype="multipart/form-data">
	<table>
      	<tr>
        	<td colspan="2">
        		<h2>增加商品</h2>
        	</td>
        </tr>
        <tr>
          	<td>商品名称：</td>
          	<td><input type="text" name="pname" id="pname"/><span></span></td>
        </tr>
        <tr>
          	<td>商品价格：</td>
         	<td><input type="text" name="price" id="price"/><span></span></td>
        </tr>
        <tr>
         	<td>库存数量：</td>
          	<td>
          		<input type="number" name="stock" id="stock"/>
         	 </td>
        </tr>
        <tr>
          	<td>商品类别：</td>
          	<td>
          		<select name="kind" id="kind">
          			<option value="">--请选择--</option>
          		</select>
          	</td>
        </tr>
        <tr>
        	<td>商品图片：</td>
        	<td>
        		<p name="imgfile">
	        		<input type="file" name="pcover"/>
	        		&nbsp;&nbsp;	
	        		<input type="button" value="删除" name="del"/>
        		</p>
        		<p><input type="button" value="增加图片" name="addimgfile"/>
        		&nbsp;&nbsp;
        		设置第<input type="number" name="iscover" value="1" min="0" style="width: 30px;"/>张图片为封面</p>
        	</td>
        </tr>
        <tr>
          	<td>商品简介：</td>
          	<td>
          		<textarea name="comments" id="comments"></textarea>
        	</td>
        </tr>
        <tr>
        	<td colspan="2">
        		<input type="submit" value="增&nbsp;&nbsp;&nbsp;&nbsp;加"/>
        	</td>
        </tr>
      </table>
    </form>
  </body>
</html>
